package com.hk.core.elasticsearch.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.domain.Persistable;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Objects;

/**
 * @author Kevin
 * @date 2019-04-14 13:17
 */
@Setter
@Getter
public abstract class AbstractSnowflakeIdPersistable implements Persistable<Long> {

    @Id
    @Field(type = FieldType.Long)
    private Long id;

    @Override
    @Transient
    @JsonIgnore
    public boolean isNew() {
        return Objects.isNull(getId());
    }
}
